let report = require('../report')
let url = require('url')

module.exports = {
  getrundata: function (req, res, next) {
    let params = url.parse(req.url, true).query
    if (params.id === undefined) {
      params = {id: 'cedc3974b7e411e787d60050c2273f5f'}
    }
    report.Config.getconfig(params).then(config => {
      report.RunData.reportRunValue(config, params.startTime, params.endTime).then(result => {
        res.send(result)
        return next()
      }).catch(msg => {
        return next()
      })
    }).catch(msg => {
      return next()
    })
  },
  getmenu: function (req, res, next) {
    report.Config.getmenu().then(result => {
      res.send(result)
      return next()
    }).catch(msg => {
      return next()
    })
  },
  addmenu: function (req, res, next) {
    report.Config.addmenu(req.body).then(result => {
      res.send(result)
      return next()
    }).catch(msg => {
      return next()
    })
  },
  getconfig: function (req, res, next) {
    var params = url.parse(req.url, true).query
    report.Config.getconfig(params).then(result => {
      res.send(result)
      return next()
    }).catch(msg => {
      return next()
    })
  },
  addconfig: function (req, res, next) {
    report.Config.addconfig(req.body).then(result => {
      res.send(result)
      return next()
    }).catch(msg => {
      return next()
    })
  }
}
